<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/jquery-3.6.0.min.js"></script>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }
        
        body {
            background: url('images/bg1.webp') no-repeat center top;
            background-size: 100% auto;
        }
        
        li {
            list-style: none;
        }
        
        .baidu {
            overflow: hidden;
            margin: 100px auto;
            background-color: #fff;
            width: 410px;
            padding-top: 3px;
        }
        
        .baidu li {
            float: left;
            margin: 0 1px;
            cursor: pointer;
        }
        
        .baidu img {
            width: 100px;
            height: 70px;
        }
    </style>
</head>

<body>

    <ul class="baidu">
        <li> <img src="images/bg1.webp" alt=""></li>
        <li> <img src="images/bg2.jpeg" alt=""></li>
        <li> <img src="images/bg3.webp" alt=""></li>
        <li> <img src="images/bg4.jpeg" alt=""></li>
    </ul>
    <!-- javascript写的
    <script>
        var imgs = document.querySelectorAll('.baidu img');
        for (var i = 0; i < imgs.length; i++) {
            imgs[i].onclick = function() {
                document.body.style.backgroundImage = 'url(' + this.src + ')';
            }
        }
    </script> -->

</body>
<!-- jQuery写的 -->
<script>
    $('.baidu img').click(function() {
        $('body').css('backgroundImage', 'url(' + $(this).attr('src') + ')');
    })
</script>
</html>